package com.example.demo.controller;

import com.example.demo.util.beanUtils.utils0.BeanConvertor;
import com.example.demo.util.beanUtils.utils0.BeanToMapUtil;
import com.example.demo.util.beanUtils.utils0.BeanUtil;
import com.example.demo.util.beanUtils.utils1.ConvertUtilss;
import com.example.demo.util.beanUtils.utils3_jeesuite.BeanUtils;
import com.example.demo.util.beanUtils.utils4.ConvertUtil_diy;
import com.example.demo.util.beanUtils.utils4.EntityMap;
import com.example.demo.util.beanUtils.utils4.EntityUtils;
import com.example.demo.util.beanUtils.utils5.BeanUtils5_2;
import com.example.demo.util.beanUtils.utils5.Util5;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping(value = "/appOrderPayLogs")
public class AppOrderPayLogsController  {


    /**
     *
     *  Integer格式的时间戳： new Integer((int) ((new Date()).getTime()/1000));  1571019029
     *
     * 传参格式：
     * {
     *     "token":"111",
     *     "paymenPlanDTOList2":{
     *         "orderNo":"11",
     * 		"periods":2,
     *         "periodsNo":1,
     *         "tradeTime":1571019029,
     *         "tradeAmount":11.002111111101,
     *         "periodsType":1,
     *         "tradeStates":0
     *     },
     *     "paymenPlanDTOList3":{
     *         "orderNo":"11",
     * 		"periods":2,
     *         "periodsNo":1,
     *         "tradeTime":"1571019029",
     *         "tradeAmount":"11.001",
     *         "periodsType":1,
     *         "tradeStates":0
     *     },
     *     "paymenPlanDTOList":[
     *                {
     *             "orderNo":"11",
     * 			"periods":"共2期",
     *             "periodsNo":"第1期",
     *             "tradeTime":"1571019029",
     *             "tradeAmount":"11"
     *         },
     *        {
     *             "orderNo":"11",
     * 			"periods":"共2期",
     *             "periodsNo":"第2期",
     *             "tradeTime":"1571019029",
     *             "tradeAmount":"12"
     *         }
     *     ]
     * }
     *
     * @param
     * @return
     */
    //回款计划配置 待确定  String orderNo, String token
    @PostMapping(value = "/paymenPlanEdit")
    public Map<String, Object> paymenPlanEdit(@RequestBody Map<String, Object> params) {
//        Map<String, Object> map=new HashMap<>();
        String token = params.get("targetExplain") + "";
        List<Map<String, Object>> listMap = (List<Map<String, Object>>) params.get("paymenPlanDTOList");
        Map<String, Object> map1 = (Map<String, Object>) params.get("paymenPlanDTOList2");
        Map<String, Object> map3 = (Map<String, Object>) params.get("paymenPlanDTOList3");

        List<OrderPayLogs> beans;
        try {
            List<Map<String, ?>> listMap$ = (List<Map<String, ?>>) params.get("paymenPlanDTOList");
            List<OrderPayLogs> objects = (List<OrderPayLogs>) BeanUtil.listMapToBeans(OrderPayLogs.class, listMap$);


            List<OrderPayLogs> orderPayLogs2 = BeanToMapUtil.convertListMap2ListBean(listMap, OrderPayLogs.class);

            OrderPayLogs orderPayLogs_4 = BeanUtil.mapToBean(map1, OrderPayLogs.class);             //ok1   commons-beanutils-1.8.0.jar           900
            OrderPayLogs orderPayLogs5_1 = BeanConvertor.mapToObject(map1, OrderPayLogs.class);     //ok3   commons-beanutils-1.8.0.jar 原理同上  114
            OrderPayLogs orderPayLogs6_1 = BeanToMapUtil.convertMap2Bean(map1, OrderPayLogs.class); //ok4   commons-beanutils-1.8.0.jar  自定义   143


            OrderPayLogs orderPayLogs4_3 = BeanUtils.mapToBean(map3, OrderPayLogs.class);           //ok20 map3有问题  map1的时候正常（无法integer->BigDecimal）

            Map<String, Object> map2 = new LinkedHashMap<>(map1);
            EntityMap map1_1 = new EntityMap(map2);
            OrderPayLogs orderPayLogs3_4 = EntityUtils.MapToEntity(map1_1, OrderPayLogs.class);     //ok 但 BigDecimal值会转换丢失
            OrderPayLogs orderPayLogs1_5 = (OrderPayLogs) Util5.map2Object(map1, OrderPayLogs.class);//正常，但数据得不到

            OrderPayLogs orderPayLogs9_5 = BeanUtils5_2.mapToBean(map1, OrderPayLogs.class);        //key11 传入类型规定较严格！且 基本数据类型无法转为BigDecimal
            Class<OrderPayLogs> orderPayLogs7_1 = ConvertUtilss.mapToBean(map1, OrderPayLogs.class); //同key11
            Class<OrderPayLogs> orderPayLogs8_5 = Util5.mapToBean(map1, OrderPayLogs.class);        //同key11

            OrderPayLogs orderPayLogs2_4 = ConvertUtil_diy.mapToBean(map1, OrderPayLogs.class);//Method threw 'java.lang.NumberFormatException' exception.


        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


}
